pacman::p_load(
rio, # import funcs
sf, # work with spatial data
here, # create relative paths
janitor, # data cleaning
lubridate, # date handling
tidyverse # data science
)
conflicted::conflict_prefer("select", "dplyr")
conflicted::conflict_prefer("filter", "dplyr")
# linelist
dat_raw <- import(here::here("data", "final", "msf_linelist_moissala_2023-09-24.xlsx"))
# lab data
lab_raw <- import(here::here("data", "final", "msf_laboratory_moissala_2023-09-24.xlsx"))
# admin data
admin_1 <- st_read(here::here("data", "gpkg", "GEO-EXPORT-TCD-2024-04-11.gpkg"), layer = "ADM1")
## Reading layer `ADM1' from data source
## `/Users/hugzsoubrier/GitHub/fake-data/data/gpkg/GEO-EXPORT-TCD-2024-04-11.gpkg'
## using driver `GPKG'
## Simple feature collection with 23 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 13.47348 ymin: 7.441069 xmax: 24.00269 ymax: 23.45037
## Geodetic CRS: WGS 84
admin_2 <- st_read(here::here("data", "gpkg", "GEO-EXPORT-TCD-2024-04-11.gpkg"), layer = "ADM2")
## Reading layer `ADM2' from data source
## `/Users/hugzsoubrier/GitHub/fake-data/data/gpkg/GEO-EXPORT-TCD-2024-04-11.gpkg'
## using driver `GPKG'
## Simple feature collection with 132 features and 9 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 13.47348 ymin: 7.441069 xmax: 24.00269 ymax: 23.45037
## Geodetic CRS: WGS 84
This document provides directions for the analysis of the fake
Measles dataset msf_linelist_moissala_2023-09-24.xlsx and
the its corresponding laboratory dataset
msf_laboratory_moissala_2023-09-24.xlsx.
For measles outbreaks, it makes sense to use the following age classification:
0 - 11 months< 6 months6 - 8 months9 - 11 months1 - 4 years5 - 14 years15+ yearsMUAC is classified as follow:
Green (125+ mm)Yellow (115 - 124 mm)Red (<115 mm)confirmed: cases with a positive PCR result in lab data
probable: cases with fever,
coughand a rash suspected: all
other cases
dat <- dat_raw |>
# standardise variable names
janitor::clean_names() |>
# manually rename
rename(
id = epi_id_number,
sex = sex_patient,
age_unit = age_units_months_years,
date_onset = date_of_onset_of_symptoms,
hospitalisation = hospitalisation_yes_no,
date_admission = date_of_admission_in_structure,
date_death = death_date,
date_exit = date_exit_of_structure,
sub_prefecture = sub_prefecture_of_residence,
region = region_of_residence,
fever = participant_had_fever,
rash = participant_had_rash,
cough = participant_had_cough,
red_eye = participant_had_red_eye,
pneumonia = participant_had_pneumonia,
encephalitis = participant_had_encephalitis,
muac = middle_upper_arm_circumference_muac,
vacc_status = vaccination_status,
vacc_doses = vaccination_dosage,
outcome = patient_outcome,
site = msf_site,
malaria_rdt = malaria_rdt
) |>
# recoding
mutate(
sex = case_when(
sex %in% c("f", "femme") ~ "female",
sex %in% c("m", "homme") ~ "male",
.default = sex
),
across(contains("date_"), ~ ymd(.x)),
across(c(fever, rash, cough, red_eye, pneumonia, encephalitis), ~ case_match(.x, "Yes" ~ TRUE, "No" ~ FALSE, .default = NA))
) |>
# Categorise variables
mutate(
age_group = case_when(
age_unit == "months" & age < 6 ~ "< 6 months",
age_unit == "months" & between(age, 6, 8) ~ "6 - 8 months",
age_unit == "months" & between(age, 9, 11) ~ "9 - 11 months",
age_unit == "years" & between(age, 1, 4) ~ "1 - 4 years",
age_unit == "years" & between(age, 5, 14) ~ "5 - 14 years",
age_unit == "years" & between(age, 15, 40) ~ "15+ years"
),
age_group = fct_relevel(
age_group,
c(
"< 6 months",
"6 - 8 months",
"9 - 11 months",
"1 - 4 years",
"5 - 14 years",
"15+ years"
)
),
muac_cat = case_when(
muac >= 125 ~ "Green (125+ mm)",
between(muac, 115, 124) ~ "Yellow (115 - 124 mm)",
muac < 115 ~ "Red (<115 mm)"
)
) |>
relocate(
age_group,
.after = age_unit
) |>
relocate(muac_cat, .after = muac)
lab_clean <- lab_raw |>
clean_names() |>
rename(
case_id = msf_number_id,
lab_id = laboratory_id,
date_test = date_of_the_test,
test_result = final_test_result
) |>
mutate(
date_test = ymd(date_test),
ct_value = round(ct_value, digits = 1)
)
There are some duplicates in the laboratory results. Some
case_id were tested multiple times if there was a
inconclusive test_result. We need to find
them, and take the last sample tested
reactable::reactable(lab_clean |> get_dupes(case_id))
lab_clean <- lab_clean |>
filter(
.by = case_id,
date_test == max(date_test, na.rm = TRUE)
)
Some samples were negative, so these cases are not cases and need to be removed from analysis
lab_clean |> count(test_result)
## test_result n
## 1 negative 59
## 2 positive 449
We join the lab_clean to the main linelists using the
case_id as key. Then remove the negative case, and create
an epidemiological classification
dat <- left_join(dat, lab_clean, by = c("id" = "case_id"))
dat <- dat |>
filter(is.na(test_result) | test_result == "positive") |>
mutate(
epi_cat = case_when(
test_result == "positive" ~ "confirmed",
rash == TRUE & fever == TRUE & cough == TRUE ~ "probable",
.default = "suspected"
),
epi_cat = fct_relevel(epi_cat, c("confirmed", "probable", "suspected"))
)
reactable::reactable(dat |> tabyl(epi_cat) |> mutate(percent = round(percent * 100, digits = 2)))
dat |>
select(
sex,
age_group,
muac_cat,
vacc_status
) |>
gtsummary::tbl_summary(label = list(
sex ~ "Gender",
age_group ~ "Age groups",
muac_cat ~ "MUAC category",
vacc_status = "Vaccination status",
malaria_rdt = "Malaria RDT",
outcome = "Outcome"
))
| Characteristic | N = 4,9691 |
|---|---|
| Gender | |
| female | 2,521 (51%) |
| male | 2,448 (49%) |
| Age groups | |
| < 6 months | 296 (6.2%) |
| 6 - 8 months | 559 (12%) |
| 9 - 11 months | 484 (10%) |
| 1 - 4 years | 2,191 (46%) |
| 5 - 14 years | 951 (20%) |
| 15+ years | 295 (6.2%) |
| Unknown | 193 |
| MUAC category | |
| Green (125+ mm) | 3,648 (73%) |
| Red (<115 mm) | 512 (10%) |
| Yellow (115 - 124 mm) | 809 (16%) |
| Vaccination status | |
| No | 2,652 (63%) |
| Uncertain | 806 (19%) |
| Yes - card | 35 (0.8%) |
| Yes - oral | 736 (17%) |
| Unknown | 740 |
| 1 n (%) | |
dat |>
select(
sex,
age_group,
muac_cat,
vacc_status,
site
) |>
gtsummary::tbl_summary(
by = site,
label = list(
sex ~ "Gender",
age_group ~ "Age groups",
muac_cat ~ "MUAC category",
vacc_status = "Vaccination status",
malaria_rdt = "Malaria RDT",
outcome = "Outcome"
)
)
| Characteristic | Bedaya Hospital, N = 8111 | Bekourou Hospital, N = 1901 | Bouna Hospital, N = 8671 | Danamadji Hospital, N = 1531 | Koumogo Hospital, N = 71 | Moïssala Hospital, N = 2,9411 |
|---|---|---|---|---|---|---|
| Gender | ||||||
| female | 401 (49%) | 105 (55%) | 449 (52%) | 71 (46%) | 4 (57%) | 1,491 (51%) |
| male | 410 (51%) | 85 (45%) | 418 (48%) | 82 (54%) | 3 (43%) | 1,450 (49%) |
| Age groups | ||||||
| < 6 months | 63 (8.0%) | 10 (5.4%) | 50 (6.0%) | 6 (4.0%) | 1 (14%) | 166 (5.9%) |
| 6 - 8 months | 99 (13%) | 23 (12%) | 93 (11%) | 14 (9.3%) | 0 (0%) | 330 (12%) |
| 9 - 11 months | 76 (9.7%) | 18 (9.7%) | 91 (11%) | 15 (10%) | 1 (14%) | 283 (10%) |
| 1 - 4 years | 347 (44%) | 84 (45%) | 388 (46%) | 78 (52%) | 3 (43%) | 1,291 (46%) |
| 5 - 14 years | 152 (19%) | 42 (23%) | 157 (19%) | 31 (21%) | 1 (14%) | 568 (20%) |
| 15+ years | 47 (6.0%) | 9 (4.8%) | 57 (6.8%) | 6 (4.0%) | 1 (14%) | 175 (6.2%) |
| Unknown | 27 | 4 | 31 | 3 | 0 | 128 |
| MUAC category | ||||||
| Green (125+ mm) | 605 (75%) | 144 (76%) | 629 (73%) | 117 (76%) | 2 (29%) | 2,151 (73%) |
| Red (<115 mm) | 82 (10%) | 21 (11%) | 92 (11%) | 12 (7.8%) | 1 (14%) | 304 (10%) |
| Yellow (115 - 124 mm) | 124 (15%) | 25 (13%) | 146 (17%) | 24 (16%) | 4 (57%) | 486 (17%) |
| Vaccination status | ||||||
| No | 423 (62%) | 107 (63%) | 445 (60%) | 90 (68%) | 2 (50%) | 1,585 (64%) |
| Uncertain | 140 (20%) | 30 (18%) | 148 (20%) | 24 (18%) | 2 (50%) | 462 (19%) |
| Yes - card | 8 (1.2%) | 2 (1.2%) | 3 (0.4%) | 1 (0.8%) | 0 (0%) | 21 (0.8%) |
| Yes - oral | 113 (17%) | 31 (18%) | 150 (20%) | 17 (13%) | 0 (0%) | 425 (17%) |
| Unknown | 127 | 20 | 121 | 21 | 3 | 448 |
| 1 n (%) | ||||||
dat |>
select(
sex,
age_group,
site
) |>
apyramid::age_pyramid(
age_group = "age_group",
split_by = "sex",
proportional = TRUE,
show_midpoint = TRUE
) +
theme_minimal()
# CFR only on known outcomes
dat |>
summarise(
.by = site,
n_cases = n(),
n_confirmed = sum(epi_cat == "confirmed"),
n_deaths = sum(outcome == "dead", na.rm = TRUE),
cfr = round(digits = 2, n_deaths / sum(outcome %in% c("recovered", "dead")) * 100)
) |>
reactable::reactable(columns = list(
n_cases = reactable::colDef(name = "N cases"),
n_confirmed = reactable::colDef(name = "N confirmed"),
n_deaths = reactable::colDef(name = "N deaths"),
cfr = reactable::colDef(name = "CFR (%)")
))
Investigating age_group, muac_cat and
vacc_status as risks factors for death
# Prepare the data for fitting the logistic regression
prep_logit <- dat |>
# change group order for references
mutate(
age_group = fct_relevel(
age_group,
c(
"15+ years",
"< 6 months",
"6 - 8 months",
"9 - 11 months",
"1 - 4 years",
"5 - 14 years"
)
),
muac_cat = fct_relevel(
muac_cat,
c(
"Green (125+ mm)",
"Yellow (115 - 124 mm)",
"Red (<115 mm)"
)
),
vacc_status = case_match(
vacc_status,
"Yes - card" ~ "Yes",
"Yes - oral" ~ "Yes",
"Uncertain" ~ NA,
.default = vacc_status
),
vacc_status = fct_relevel(
vacc_status,
c(
"No",
"Yes"
)
),
# outcome needs to be 1/0
outcome_binary = case_when(
outcome == "recovered" ~ 0,
outcome == "dead" ~ 1,
.default = NA
)
)
# fit the logistic regression
mdl <- glm(outcome_binary ~ sex + age_group + vacc_status + muac_cat, data = prep_logit, family = "binomial")
# view coeff
gtsummary::tbl_regression(
mdl,
exp = TRUE,
label = list(
sex ~ "Gender",
age_group ~ "Age groups",
muac_cat ~ "MUAC category",
vacc_status = "Vaccination status"
),
intercept = TRUE,
conf.int = TRUE
)
| Characteristic | OR1 | 95% CI1 | p-value |
|---|---|---|---|
| (Intercept) | 0.01 | 0.00, 0.03 | <0.001 |
| Gender | |||
| female | — | — | |
| male | 0.86 | 0.67, 1.11 | 0.2 |
| Age groups | |||
| 15+ years | — | — | |
| < 6 months | 37.6 | 7.91, 673 | <0.001 |
| 6 - 8 months | 25.7 | 5.52, 458 | 0.001 |
| 9 - 11 months | 24.8 | 5.28, 443 | 0.002 |
| 1 - 4 years | 13.6 | 2.99, 241 | 0.010 |
| 5 - 14 years | 8.21 | 1.70, 148 | 0.041 |
| Vaccination status | |||
| No | — | — | |
| Yes | 0.25 | 0.15, 0.39 | <0.001 |
| MUAC category | |||
| Green (125+ mm) | — | — | |
| Yellow (115 - 124 mm) | 1.89 | 1.36, 2.60 | <0.001 |
| Red (<115 mm) | 3.69 | 2.65, 5.09 | <0.001 |
| 1 OR = Odds Ratio, CI = Confidence Interval | |||
dat |>
mutate(
epiweek = floor_date(date_onset, unit = "week")
) |>
ggplot() +
geom_bar(
aes(
x = epiweek,
fill = epi_cat
),
position = position_stack()
) +
scale_x_date(
breaks = "2 weeks",
date_labels = "%Y -W%W"
) +
scale_fill_manual(
"Epi status",
values = c(
"confirmed" = "#912c2c",
"probable" = "#c4833d",
"suspected" = "#edd598"
)
) +
labs(
x = "Epiweek",
y = "N cases",
title = glue::glue("Epicurve of measle outbreak in Southern Chad"),
subtitle = glue::glue({
"{nrow(dat)} cases observed from {min(dat$date_onset, na.rm = TRUE)} to {max(dat$date_onset, na.rm = TRUE)}"
})
) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, size = 5))
dat |>
mutate(
epiweek = floor_date(date_onset, unit = "week")
) |>
ggplot() +
geom_bar(
aes(
x = epiweek,
fill = site
),
position = position_stack()
) +
scale_x_date(
breaks = "4 weeks",
date_labels = "%Y -W%W"
) +
labs(
x = "Epiweek",
y = "N cases",
title = glue::glue("Epicurve of measle outbreak in Southern Chad"),
subtitle = glue::glue({
"{nrow(dat)} cases observed from {min(dat$date_onset, na.rm = TRUE)} to {max(dat$date_onset, na.rm = TRUE)}"
})
) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, size = 5)) +
facet_wrap(~site) +
gghighlight::gghighlight()
Make a Choropleth map
# clean admin data
dat <- dat |>
mutate(across(c(sub_prefecture, region), ~ str_to_sentence(.x)))
# count cases by adm2
adm_summ <- dat |> summarise(
.by = c(region, sub_prefecture),
n_cases = n(),
n_deaths = sum(outcome == "dead", na.rm = TRUE),
cfr = round(digits = 3, n_deaths / sum(outcome %in% c("recovered", "dead", na.rm = TRUE))),
cfr_lab = scales::percent(cfr, accuracy = .1)
)
# join the count data to the sf
chor_dat <- left_join(
admin_2,
adm_summ,
by = c("adm2_name" = "sub_prefecture")
) |>
# add AR using population data
mutate(
AR = round(digits = 3, n_cases / adm2_pop * 1000),
label = (paste0(
"<b>Region:</b> ",
adm1_name,
"<br><b>Sub-prefecture:</b> ",
adm2_name,
"<br><b>Population:</b> ",
adm2_pop,
"<br><b>Attack Rate:</b> ",
AR,
"<br><b>CFR (%):</b> ",
cfr_lab
))
)
leaf_basemap <- function(
bbox,
baseGroups = c("Light", "OSM", "OSM HOT"),
overlayGroups = c("Boundaries"),
miniMap = TRUE
) {
lf <- leaflet::leaflet() %>%
leaflet::fitBounds(bbox[["xmin"]], bbox[["ymin"]], bbox[["xmax"]], bbox[["ymax"]]) %>%
leaflet::addMapPane(name = "choropleth", zIndex = 310) %>%
leaflet::addMapPane(name = "place_labels", zIndex = 320) %>%
leaflet::addMapPane(name = "circles", zIndex = 410) %>%
leaflet::addMapPane(name = "boundaries", zIndex = 420) %>%
leaflet::addMapPane(name = "geo_highlight", zIndex = 430) %>%
leaflet::addProviderTiles("CartoDB.PositronNoLabels", group = "Light") %>%
leaflet::addProviderTiles(
"CartoDB.PositronOnlyLabels",
group = "Light",
options = leaflet::leafletOptions(pane = "place_labels")
) %>%
leaflet::addProviderTiles("OpenStreetMap", group = "OSM") %>%
leaflet::addProviderTiles("OpenStreetMap.HOT", group = "OSM HOT") %>%
leaflet::addScaleBar(
position = "bottomright",
options = leaflet::scaleBarOptions(imperial = FALSE)
) %>%
leaflet::addLayersControl(
baseGroups = baseGroups,
overlayGroups = overlayGroups,
position = "topleft"
)
if (miniMap) {
lf <- lf %>% leaflet::addMiniMap(toggleDisplay = TRUE, position = "bottomleft")
}
return(lf)
}
bbox <- st_bbox(filter(admin_2, adm1_name == "Mandoul"))
bins <- c(0, 1, 5, 10, 20, Inf)
pal <- leaflet::colorBin("YlOrRd", domain = chor_dat$AR, bins = bins)
labels <- chor_dat$label |> lapply(htmltools::HTML)
leaflet::leaflet() |>
leaf_basemap(bbox, miniMap = TRUE) |>
leaflet::fitBounds(as.character(bbox)[1], as.character(bbox)[2], as.character(bbox)[3], as.character(bbox)[4]) |>
leaflet::addProviderTiles("CartoDB.Positron", group = "Light") |>
leaflet::addScaleBar(position = "bottomright", options = leaflet::scaleBarOptions(imperial = FALSE)) |>
leaflet.extras::addFullscreenControl(position = "topleft") |>
leaflet.extras::addResetMapButton() |>
leaflet::addPolygons(
data = admin_1,
stroke = TRUE,
weight = 1.5,
color = "black",
fill = FALSE,
fillOpacity = 0
) |>
leaflet::addPolygons(
data = chor_dat,
label = ~labels,
stroke = TRUE,
weight = 1.2,
color = "grey",
fillColor = ~ pal(AR),
fillOpacity = 0.3
)